﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jsMessage.aspx.cs" Inherits="tjb.WebTest.JsMessage_TextBoxbehind.jsMessage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <script language="javascript" type="text/javascript">
function $() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (arguments.length == 1)
            return element;
        elements.push(element);
    }
    return elements;
}
    
String.prototype.len=function(){ 
return this.replace(/[^\x00-\xff]/g,"**").length; 
}       
function fetchOffset(obj) {
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;
	var width_offset =obj.offsetWidth;
	var height_offset = obj.offsetHeight;
	while((obj = obj.offsetParent) != null) {
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}
	return { 'left' : left_offset, 'top' : top_offset,'width' :width_offset,'height':height_offset  };
}
var  __msgTimer=null;
function CheckLength(src,min,max){
    src =$(src);
    if(src){
        var ___msgViewid="___msgView";
        var offset =fetchOffset(src);
        var ___msgView = $(___msgViewid);
        if(!___msgView){
            ___msgView = document.createElement("div");
            ___msgView.id=___msgViewid;
            ___msgView.style.position="absolute";
            ___msgView.style.color="red";
            document.body.appendChild(___msgView);
        }
        ___msgView.style.top =offset.top+"px";
        ___msgView.style.left=(offset.left + offset.width)+"px";
            
        var __msg= "";
        
        var curLen=src.value.len();
        window.status =curLen + "top:" +___msgView.style.top +"|left:"+___msgView.style.left;
        if(min && min>0 && min > curLen){
            __msg ="长度必须不少于"+min+"位";
            window.clearTimeout(__msgTimer);
        }
        else if(max && max >0 && max <curLen)
        {
            __msg ="长度不能大于"+max+"位";
             window.clearTimeout(__msgTimer);
        }
        else if(max && max >0 && max >curLen){
            __msg ="还可以输入"+(max -curLen)+"个字符";
        }
        else
        {
            __msg  ="正确";
              window.clearTimeout(__msgTimer);
            __msgTimer=window.setTimeout(function(){___msgView.style.display='none';},3000);
        }
        ___msgView.style.display="block";
        ___msgView.innerHTML =__msg;
    }
    else
    {
        window.status ="深潭碧波，寂清静宁！";
    }
}

    
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" onkeyup="CheckLength(this,0,18)" runat="server"></asp:TextBox>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <asp:TextBox ID="TextBox3" onkeyup="CheckLength(this,3,15)" runat="server" 
            TextMode="Password"></asp:TextBox>
        <br />
        <br />
        <br />
        <br />
        <asp:TextBox ID="TextBox2" onkeyup="CheckLength(this,6,11)" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>
